<template>
  <div class="department" id="department collapse-itemContent">
    <!-- 左侧部门管理 -->
    <div class="structureTree" v-if="treelength">
      <div class="structureTree_title">
        <div>组织机构</div>
        <div></div>
      </div>
      <tree
        :treeData="treeData"
        :checkData="checkData"
        nodeKey="fCompanyid"
        @getTreeInfo="handleNodeClick"
        :defaultProps="defaultProps"
      >
      </tree>
    </div>
    <!-- 右侧 -->
    <div class="department_right">
      <!-- 机构名称 -->
      <el-breadcrumb :title="showName"></el-breadcrumb>
      <!-- 表格 -->
      <div
        class="warningObject_table tableminute collapse-itemContent"
        id="tableminute collapse-itemContent"
      >
        <el-collapse
          v-if="!pageFlag"
          v-model="activeNames"
          @change="changeCollapse"
        >
          <el-collapse-item name="0">
            <template slot="title">
              <div>
                <img
                  style="vertical-align: middle"
                  src="@/assets/img/Supervision/com_flg.png"
                  alt=""
                />
                <span style="margin-left: 8px"
                  >按每盘混合料单一材料的重量偏差提醒</span
                >
              </div>
            </template>
            <div style="margin-top: 3px; display: flex; flex-direction: column">
              <div>
                <el-table
                  :data="tableData"
                  :span-method="objectSpanMethod"
                  border
                  style="width: 100%"
                >
                  <el-table-column
                    prop="type"
                    label=""
                    align="center"
                    width="180"
                  >
                    <template slot-scope="scope">
                      <el-button
                        :type="
                          scope.row.type == 1
                            ? 'plain'
                            : scope.row.type == 2
                            ? 'warning'
                            : scope.row.type == 3
                            ? 'danger'
                            : scope.row.type == 4
                            ? 'purple'
                            : 'brown'
                        "
                        :class="
                          scope.row.type == 1
                            ? 'plain'
                            : scope.row.type == 2
                            ? 'warning'
                            : scope.row.type == 3
                            ? 'danger'
                            : scope.row.type == 4
                            ? 'purple'
                            : 'brown'
                        "
                        >{{ scope.row.type | typ1 }}</el-button
                      >
                    </template>
                  </el-table-column>

                  <el-table-column prop="name" label="报警对象" align="center">
                    <template slot-scope="scope">
                      <div class="selectobject">
                        <el-select
                          placeholder="请选择"
                          v-model="scope.row.name"
                          multiple
                          value-key="fId"
                          @change="selectEquipmen(scope.row, scope.row.name)"
                        >
                          <el-option
                            v-for="(item, index) in ObjectsData"
                            :label="`${item.fObjectname}`"
                            :value="item"
                            :key="index"
                          >
                          </el-option>
                        </el-select>
                      </div>
                    </template>
                  </el-table-column>

                  <el-table-column
                    prop="amount1"
                    label="超出多少周期后不发(分钟)"
                    align="center"
                  >
                    <template slot-scope="scope">
                      <div class="inputminute">
                        <el-input
                          v-model="scope.row.amount1"
                          type="number"
                        ></el-input>
                      </div>
                    </template>
                  </el-table-column>

                  <el-table-column
                    prop="amount2"
                    label="是否启动"
                    align="center"
                  >
                    <template slot-scope="scope">
                      <el-switch v-model="scope.row.amount2"> </el-switch>
                    </template>
                  </el-table-column>
                </el-table>
              </div>

              <div style="margin: 5px 0" class="shortMessageform">
                <el-form ref="form" :model="form" label-width="180px">
                  <el-form-item label="短信模板">
                    <el-input type="textarea" v-model="form.desc"></el-input>
                  </el-form-item>
                </el-form>
                <div style="margin-left: 180px; color: #f78989">
                  说明 {0}：表示“标段” {1}：表示“工程名称” {2}：表示“工程部位”
                  {3}：表示“拌合站名称” {4}：表示“拌合机名称”
                  {5}：表示“拌合机编号” {6}：表示“出料时间” {7}：表示“强度等级”
                  {8}：表示“超标等级” {9}：表示“超标结果”
                </div>
              </div>
              <!-- 保存按钮 -->
              <div class="saveBtn">
                <el-button
                  type="primary"
                  size="small"
                  @click="yj_editObjectForm(0)"
                >
                  保存</el-button
                >
              </div>
            </div>
          </el-collapse-item>

          <el-collapse-item name="1">
            <template slot="title">
              <div>
                <img
                  style="vertical-align: middle"
                  src="@/assets/img/Supervision/com_flg.png"
                  alt=""
                />
                <span style="margin-left: 8px"
                  >按每车混合料单一材料的重量偏差提醒</span
                >
              </div>
            </template>
            <div style="margin-top: 3px">
              <div>
                <el-table
                  :data="tableData3"
                  :span-method="objectSpanMethod"
                  border
                  style="width: 100%"
                >
                  <el-table-column
                    prop="type"
                    label=""
                    align="center"
                    width="180"
                  >
                    <template slot-scope="scope">
                      <el-button
                        :type="
                          scope.row.type == 1
                            ? 'plain'
                            : scope.row.type == 2
                            ? 'warning'
                            : 'danger'
                        "
                        :class="
                          scope.row.type == 1
                            ? 'plain'
                            : scope.row.type == 2
                            ? 'warning'
                            : 'danger'
                        "
                        >{{ scope.row.type | type }}</el-button
                      >
                    </template>
                  </el-table-column>
                  <el-table-column prop="name" label="报警对象" align="center">
                    <template slot-scope="scope">
                      <div class="selectobject">
                        <el-select
                          placeholder="请选择"
                          v-model="scope.row.name"
                          multiple
                          value-key="fId"
                          @change="selectEquipmen(scope.row, scope.row.name)"
                        >
                          <el-option
                            v-for="(item, index) in ObjectsData"
                            :label="`${item.fObjectname}`"
                            :value="item"
                            :key="index"
                          >
                          </el-option>
                        </el-select>
                      </div>
                    </template>
                  </el-table-column>
                  <el-table-column
                    prop="amount1"
                    label="超出多少周期后不发(分钟)"
                    align="center"
                  >
                    <template slot-scope="scope">
                      <div class="inputminute">
                        <el-input
                          v-model="scope.row.amount1"
                          type="number"
                        ></el-input>
                      </div>
                    </template>
                  </el-table-column>
                  <el-table-column
                    prop="amount2"
                    label="是否启动"
                    align="center"
                  >
                    <template slot-scope="scope">
                      <el-switch v-model="scope.row.amount2"> </el-switch>
                    </template>
                  </el-table-column>
                </el-table>
              </div>
              <div style="margin: 5px 0" class="shortMessageform">
                <el-form ref="form" :model="form3" label-width="180px">
                  <el-form-item label="短信模板">
                    <el-input type="textarea" v-model="form3.desc"></el-input>
                  </el-form-item>
                </el-form>
              </div>
              <div style="margin-left: 180px; color: #f78989">
                说明 {0}：表示“标段” {1}：表示“工程名称” {2}：表示“工程部位”
                {3}：表示“拌合站名称” {4}：表示“拌合机名称”
                {5}：表示“拌合机编号” {6}：表示“车牌号” {7}：表示“出料时间”
                {8}：表示“强度等级” {9}：表示“超标等级” {10}：表示“超标结果”
              </div>
              <!-- 保存按钮 -->
              <div class="saveBtn">
                <el-button
                  type="primary"
                  size="small"
                  @click="yj_editObjectForm(1)"
                >
                  保存</el-button
                >
              </div>
            </div>
          </el-collapse-item>
          <el-collapse-item name="2">
            <template slot="title">
              <div>
                <img
                  style="vertical-align: middle"
                  src="@/assets/img/Supervision/com_flg.png"
                  alt=""
                />
                <span style="margin-left: 8px"
                  >按照一段时间内不合格的盘数提醒</span
                >
              </div>
            </template>
            <div style="margin-top: 3px">
              <div class="customTableTotal">
                <!--  :data="tableData2.filter(data => !search || data.name.toLowerCase().includes(search.toLowerCase()))" -->
                <el-table :data="tableData2" style="width: 100%">
                  <el-table-column
                    prop="fSendobject"
                    label="发送对象"
                    align="center"
                  >
                    <template slot-scope="scope">
                      <div class="selectobject">
                        <el-select
                          placeholder="请选择"
                          v-model="scope.row.fSendobject"
                          value-key="fId"
                          @change="
                            selectEquipmen(scope.row, scope.row.fSendobject)
                          "
                        >
                          <el-option
                            v-for="(item, index) in ObjectsData"
                            :label="`${item.fObjectname}`"
                            :value="item"
                            :key="index"
                          >
                          </el-option>
                        </el-select>
                      </div>
                    </template>
                  </el-table-column>
                  <el-table-column
                    prop="fSendperiod"
                    label="发送周期(0~59分钟)"
                    align="center"
                  >
                    <template slot-scope="scope">
                      <div class="inputminute">
                        <el-input
                          @input="minuteScope($event, scope)"
                          v-model="scope.row.fSendperiod"
                          type="number"
                          min="0"
                          max="59"
                        ></el-input>
                      </div>
                    </template>
                  </el-table-column>
                  <el-table-column
                    prop="fUnqualifiedcount"
                    label="不合格盘数"
                    align="center"
                  >
                    <template slot-scope="scope">
                      <div class="inputminute">
                        <el-input
                          v-model="scope.row.fUnqualifiedcount"
                        ></el-input>
                      </div>
                    </template>
                  </el-table-column>
                  <el-table-column
                    prop="fIsstarted"
                    label="是否启动"
                    align="center"
                  >
                    <template slot-scope="scope">
                      <el-switch v-model="scope.row.fIsstarted"> </el-switch>
                    </template>
                  </el-table-column>
                  <el-table-column align="right">
                    <template slot="header">
                      <div class="customTable">
                        <el-button
                          type="primary"
                          icon="el-icon-circle-plus-outline"
                          @click="addUnqualifiedInfo"
                        ></el-button>
                      </div>
                    </template>
                    <template slot-scope="scope">
                      <div class="customTable" style="padding-right: 37px">
                        <el-button
                          type="danger"
                          icon="el-icon-delete"
                          @click="
                            deleteUnqualifiedInfo(scope.$index, scope.row)
                          "
                          circle
                        ></el-button>
                      </div>
                    </template>
                  </el-table-column>
                </el-table>
              </div>
              <div style="margin: 5px 0" class="shortMessageform">
                <el-form ref="form" :model="form2" label-width="180px">
                  <el-form-item label="短信模板">
                    <el-input type="textarea" v-model="form2.desc"></el-input>
                  </el-form-item>
                </el-form>
              </div>
              <div style="margin-left: 180px; color: #f78989">
                说明 {0}：表示“标段” {1}：表示“拌合机名称” {2}：表示“发送周期”
                {3}：表示“超标盘数” {4}：表示“最近出料时间”
              </div>
              <!-- 保存按钮 -->
              <div class="saveBtn">
                <el-button
                  type="primary"
                  size="small"
                  @click="yj_editObjectForm(2)"
                >
                  保存</el-button
                >
              </div>
            </div>
          </el-collapse-item>
          <el-collapse-item name="3">
            <template slot="title">
              <div>
                <img
                  style="vertical-align: middle"
                  src="@/assets/img/Supervision/com_flg.png"
                  alt=""
                />
                <span style="margin-left: 8px">昨日不合格总量进行提醒</span>
              </div>
            </template>
            <div style="margin-top: 3px">
              <div>
                <el-table :data="tableData1" border style="width: 100%">
                  <el-table-column prop="name" label="报警对象" align="center">
                    <template slot-scope="scope">
                      <div class="selectobject">
                        <el-select
                          placeholder="请选择"
                          v-model="scope.row.name"
                          multiple
                          value-key="fId"
                          @change="selectEquipmen(scope.row, scope.row.name)"
                        >
                          <el-option
                            v-for="(item, index) in ObjectsData"
                            :label="`${item.fObjectname}`"
                            :value="item"
                            :key="index"
                          >
                          </el-option>
                        </el-select>
                      </div>
                    </template>
                  </el-table-column>
                  <el-table-column
                    prop="amount1"
                    label="发送时间(有效范围0-23)"
                    align="center"
                  >
                    <template slot-scope="scope">
                      <div class="inputminute">
                        <el-input
                          @input="timeScope"
                          v-model="scope.row.amount1"
                          type="number"
                          min="0"
                          max="23"
                        ></el-input>
                      </div>
                    </template>
                  </el-table-column>
                  <el-table-column
                    prop="amount2"
                    label="是否启动"
                    align="center"
                  >
                    <template slot-scope="scope">
                      <el-switch v-model="scope.row.amount2"> </el-switch>
                    </template>
                  </el-table-column>
                </el-table>
              </div>
              <div style="margin: 5px 0" class="shortMessageform">
                <el-form ref="form" :model="form1" label-width="180px">
                  <el-form-item label="短信模板">
                    <el-input type="textarea" v-model="form1.desc"></el-input>
                  </el-form-item>
                </el-form>
              </div>
              <div style="margin-left: 180px; color: #f78989">
                说明 {0}：表示“标段” {1}：表示“拌合机编号”
                {2}：表示“昨日累计盘数” {3}：表示“昨日累计超标盘数”
                {4}：表示“代表总方量” {5}：表示“超标方量” {6}：表示“超标率”
              </div>
              <!-- 保存按钮 -->
              <div class="saveBtn">
                <el-button
                  type="primary"
                  size="small"
                  @click="yj_editObjectForm(3)"
                >
                  保存</el-button
                >
              </div>
            </div>
          </el-collapse-item>
        </el-collapse>
        <div v-if="pageFlag" class="pageFlag">
          <img src="@/assets/img/undata.png" alt="" />
          <div class="pageFlagText">暂时没有数据哦！</div>
          <div class="pageFlagTexts">请选择施工单位</div>
        </div>
      </div>
    </div>
  </div>
</template>
<script>
import tree from "@/components/public/el-trees"; //左侧机构树
// import TableData from '@/components/public/el-table';
import elBreadcrumb from "@/components/public/el-breadcrumb.vue";
// import publicForm from "@/components/public/el-form.vue"
import {
  getUserCompanyTreeList, //树状图接口
  getNoticeObjectListByCompanyId, //预警通知-对象列表页
  getNoticeTemplateByPiece, // 按盘数模版--获取
  addNoticeTemplateByPiece, // 按盘数模版--新增/修改
  getNoticeTemplateByTruck, // 按每车模版--获取
  addNoticeTemplateByTruck, // 按每车模版--新增/修改
  getNoticeTemplateByTime, // 按一段时间模版--获取
  addNoticeTemplateByTime, // 按一段时间模版--新增/修改
  getNoticeTemplateByYesterday, // 按昨日不合格总量模版--获取
  addNoticeTemplateByYesterday, // 按昨日不合格总量模版--新增/修改
} from "@/api/request.js";

// import { objectType, messageType } from "@/utils/config";
export default {
  name: "warningInformation",
  inject: ["reload"],
  data() {
    return {
      name: "warningInformation", //按钮配置页面代号
      // 机构树
      treelength: false, //左侧树显示隐藏
      checkData: [], //选中tree状态id
      defaultProps: {
        children: "children",
        label: "fShortname",
      },
      showName: "未选择公司",
      treeData: [], //左侧树状图数据
      fNature: "", //点击组织机构等级
      treeText: {
        //树状图参数
        companyId: null,
        userId: null,
        text: null,
      },
      // 机构树
      pageFlag: true, //判断是否在施工单位级别
      activeNames: ["0", "1", "2", "3"], //折叠面板

      // 按盘数模版--参数
      addList_p: {
        fId: "", // 为空或不传时新增  有值为修改
        userId: "", // 当前用户id
        userName: "", // 当前用户name
        fCompanyid: "", // 施工标段id
        fLowobjectids: "", // 初级对象ids
        fMidobjectids: "", // 中级对象ids
        fHighobjectids: "", // 高级对象ids
        fBetterhighobjectids: "", // 四级对象ids
        fMosthighobjectids: "", // 五级对象ids
        fOvertime: "", // 超出多少周期后不发
        fIsstarted: "", // 是否启用 1 启用 0-停用
        fTexttemplate: "", // 短信模版
        fNote: "1",
      },
      tableData: [
        //  按每盘 数据
        {
          type: "1",
          name: [],
          amount1: "",
          amount2: true,
        },
        {
          type: "2",
          name: [],
          amount1: "",
          amount2: "",
        },
        {
          type: "3",
          name: [],
          amount1: "",
          amount2: "",
        },
        {
          type: "4",
          name: [],
          amount1: "",
          amount2: "",
        },
        {
          type: "5",
          name: [],
          amount1: "",
          amount2: "",
        },
      ],
      form: {
        desc: "提示:{0} {1} {2},{3}({5}),出料时间{6},{7},{8}超差,{9}，请及时查看。",
      },
      // 按盘数模版--参数

      // 按车模版--参数
      addList_C: {
        fId: "", // 为空或不传时新增  有值为修改
        userId: "", // 当前用户id
        userName: "", // 当前用户name
        fCompanyid: "", // 施工标段id
        fLowobjectids: "", // 初级对象ids
        fMidobjectids: "", // 中级对象ids
        fHighobjectids: "", // 高级对象ids
        fOvertime: "", // 超出多少周期后不发
        fIsstarted: "", // 是否启用 1 启用 0-停用
        fTexttemplate: "", // 短信模版
        fNote: "1",
      },
      tableData3: [
        //  按每盘 数据
        {
          type: "1",
          name: [],
          amount1: "",
          amount2: true,
        },
        {
          type: "2",
          name: [],
          amount1: "",
          amount2: "",
        },
        {
          type: "3",
          name: [],
          amount1: "",
          amount2: "",
        },
      ],
      form3: {
        desc: "提示:按每车混合料单一材料的重量偏差提醒。",
      },
      // 按车模版--参数

      // 按时间模版--参数
      tableData2: [],
      form2: {
        desc: "提示:按时间",
      },
      // 按时间模版--参数

      // 按昨天模版--参数
      addList_D: {
        fId: "", // fid 为空或不传时新增  有值时为修改
        userId: "", // 当前登陆用户id
        userName: "", // 当前登陆用户name
        fCompanyid: "", // 施工标段id
        fSendobject: "", // 发送对象
        fSendtime: "", //发送时间
        fIsstarted: "", // 是否启用 0-禁用 1-启用
        fTexttemplate: "", //短信模版
        fNote: "1",
      },
      form1: {
        desc: "提示:{0},{1},昨日累计生产{2}盘,其中有{3}盘偏差过大,总方量为{4},超标方量为{5},超标率为{6},请及时查看。",
      },

      tableData1: [
        {
          type: "1",
          name: [],
          amount1: "",
          amount2: true,
        },
      ],
      // 按昨天模版--参数
      ObjectsData: [], //报警对象下拉框
      fEquipmentname: [], //已选主要仪器设备
      getList: {
        fCompanyid: "", // 施工标段id
      },

      //   yj_add: null, //新增按钮是否显示
      //   yj_edit: null, //编辑按钮是否显示
      //   yj_view: null, //查看按钮是否显示
    };
  },
  components: {
    tree, //左侧组织机构数
    elBreadcrumb, //面包屑
  },
  filters: {
    type(val) {
      var type;
      if (val == 1) {
        type = "初级";
      } else if (val == 2) {
        type = "中级";
      } else if (val == 3) {
        type = "高级";
      }
      return type;
    },
    typ1(val) {
      var type;
      if (val == 1) {
        type = "一级";
      } else if (val == 2) {
        type = "二级";
      } else if (val == 3) {
        type = "三级";
      } else if (val == 4) {
        type = "四级";
      } else if (val == 5) {
        type = "五级";
      }
      return type;
    },
  },
  mounted() {
    if (JSON.parse(sessionStorage.getItem("treeCheck"))) {
      var id = JSON.parse(sessionStorage.getItem("treeCheck"));
      this.checkData = [id.fCompanyid];
      this.getList.fCompanyid = id.fCompanyid;

      if (id.fNature == "施工单位") {
        this.pageFlag = false;
        this.yj_ObjectForm(id.fCompanyid);
        this.getFormwork_P(id.fCompanyid);
        this.getFormwork_C(id.fCompanyid);
        this.getFormwork_T(id.fCompanyid);
        this.getFormwork_D(id.fCompanyid);
      } else {
        this.pageFlag = true;
      }
    }
    this.getTree();
    this.btnRole(this.name);
  },
  methods: {
    btnRole(name) {
      // 按钮权限
      var btnList = [];
      var ModuleList = JSON.parse(sessionStorage.getItem("ModuleList"));
      if (ModuleList.length > 0) {
        ModuleList.map((item) => {
          if (item.fEncode == name) {
            btnList = item.modulebuttonList;
          }
        });
        var btnStr = [];
        btnList.map((item) => {
          btnStr.push(item.fEncode);
        });

        this.yj_add = btnStr.includes("yj_add");
        this.yj_edit = btnStr.includes("yj_edit");
        this.yj_view = btnStr.includes("yj_view");
      } else {
        this.yj_add = true;
        this.yj_edit = true;
        this.yj_view = true;
      }
    },

    // 折叠面板
    changeCollapse(e) {
      return e;
    },

    // 昨日不合格总量进行提醒  发送时间
    timeScope(e) {
      if (e - 0 < 0) {
        this.tableData1[0].amount1 = "0";
      } else if (e - 0 > 23) {
        this.tableData1[0].amount1 = "23";
      } else {
        this.tableData1[0].amount1 = e;
      }
    },
    // 按照一段时间内不合格的盘数提醒
    minuteScope(e, row) {
      if (e - 0 < 0) {
        this.tableData2[row.$index].fSendperiod = "0";
      } else if (e - 0 > 59) {
        this.tableData2[row.$index].fSendperiod = "59";
      } else {
        this.tableData2[row.$index].fSendperiod = e;
      }
    },
    // 添加按照一段时间内不合格的盘数提醒
    addUnqualifiedInfo() {
      this.tableData2.push({
        fId: "", // 为空或不传时新增  有值为修改
        userId: this.$store.state.userInfo.userId, // 当前用户id
        userName: this.$store.state.userInfo.realName, // 当前用户name
        fCompanyid: this.getList.fCompanyid, // 施工标段id
        fSendobject: "", // 发送对象id
        fSendperiod: "", // 发送周期
        fUnqualifiedcount: "", // 不合格盘数
        fIsstarted: true, // 是否启动 0-否   1-是
        fTexttemplate: this.form2.desc, // 短信模版
        fNote: "1",
      });
    },
    // 删除按照一段时间内不合格的盘数提醒
    deleteUnqualifiedInfo(index) {
      this.tableData2.splice(index, 1);
    },

    objectSpanMethod({ columnIndex }) {
      // 合并列
      if (columnIndex === 2 || columnIndex === 3) {
        return {
          rowspan: 5,
          colspan: 1,
        };
      }
    },
    // 左侧树结构
    getTree() {
      this.treeText = {
        companyId: this.$store.state.userInfo.companyId,
        userId: this.$store.state.userInfo.userId,
        text: "1", // 0其他  1 砼拌合站 2水稳 3沥青
      };
      getUserCompanyTreeList(this.treeText)
        .then((res) => {
          if (res.errcode == 0) {
            var companyTree = res.data.userCompanyTreeList;
            this.treeData = this.commonJs.tranListToTreeData(companyTree);

            if (this.treeData[0].children == undefined) {
              this.treelength = false; //左侧组织机构是否显示
            } else {
              this.treelength = true;
            }
            if (this.checkData[0]) {
              this.showName = JSON.parse(
                sessionStorage.getItem("treeCheck")
              ).fShortname;
              this.addList_p.fCompanyid = this.checkData[0]; // 施工标段id
              this.addList_C.fCompanyid = this.checkData[0];
              this.addList_D.fCompanyid = this.checkData[0];
            } else {
              this.showName = this.treeData[0].fShortname; //当前点击组织机构名称
              this.checkData[0] = this.treeData[0].fCompanyid;
            }
          } else {
            this.$message.error(res.msg);
            return false;
          }
        })
        .catch(() => {
          return false;
        });
    },

    // 点击左侧机构树
    handleNodeClick(data) {
      this.showName = data.fShortname; //顶部显示机构名
      this.fNature = data.fNature;
      if (data.fNature == "施工单位") {
        this.reload();
        this.addList_p.fCompanyid = data.fCompanyid; // 按盘 施工标段id
        this.addList_C.fCompanyid = data.fCompanyid; // 按车 施工标段id
        this.addList_D.fCompanyid = data.fCompanyid; // 按昨日 施工标段id

        this.pageFlag = false;
        this.getList.fCompanyid = data.fCompanyid; //当前点击组织机构ID

        this.yj_ObjectForm(data.fCompanyid);

        this.getFormwork_P(data.fCompanyid);
        this.getFormwork_C(data.fCompanyid);
        this.getFormwork_T(data.fCompanyid);
        this.getFormwork_D(data.fCompanyid);
      } else {
        this.pageFlag = true;
      }
    },

    getFormwork_P(id) {
      // 按盘数模版--获取
      getNoticeTemplateByPiece({ fCompanyid: id, fNote: "1" })
        .then((res) => {
          if (res.errcode == 0) {
            if (res.data) {
              this.addList_p.fId = res.data.fId;

              let fLowobjectidsArr = null;
              this.tableData[0].name = [];
              fLowobjectidsArr = res.data.fLowobjectids.split(",");
              for (let index = 0; index < this.ObjectsData.length; index++) {
                const element = this.ObjectsData[index];
                for (let index = 0; index < fLowobjectidsArr.length; index++) {
                  const element1 = fLowobjectidsArr[index];
                  if (element.fId == element1) {
                    this.tableData[0].name.push(element);
                  }
                }
              }

              let fMidobjectidsArr = null;
              this.tableData[1].name = [];
              fMidobjectidsArr = res.data.fMidobjectids.split(",");
              for (let index = 0; index < this.ObjectsData.length; index++) {
                const element = this.ObjectsData[index];
                for (let index = 0; index < fMidobjectidsArr.length; index++) {
                  const element1 = fMidobjectidsArr[index];
                  if (element.fId == element1) {
                    this.tableData[1].name.push(element);
                  }
                }
              }

              let fHighobjectidsArr = null;
              this.tableData[2].name = [];
              fHighobjectidsArr = res.data.fHighobjectids.split(",");
              for (let index = 0; index < this.ObjectsData.length; index++) {
                const element = this.ObjectsData[index];
                for (let index = 0; index < fHighobjectidsArr.length; index++) {
                  const element1 = fHighobjectidsArr[index];
                  if (element.fId == element1) {
                    this.tableData[2].name.push(element);
                  }
                }
              }

              let fBetterhighobjectidsArr = null;
              this.tableData[3].name = [];
              fBetterhighobjectidsArr =
                res.data.fBetterhighobjectids.split(",");
              for (let index = 0; index < this.ObjectsData.length; index++) {
                const element = this.ObjectsData[index];
                for (
                  let index = 0;
                  index < fBetterhighobjectidsArr.length;
                  index++
                ) {
                  const element1 = fBetterhighobjectidsArr[index];
                  if (element.fId == element1) {
                    this.tableData[3].name.push(element);
                  }
                }
              }

              let fMosthighobjectidsArr = null;
              this.tableData[4].name = [];
              fMosthighobjectidsArr = res.data.fMosthighobjectids.split(",");
              for (let index = 0; index < this.ObjectsData.length; index++) {
                const element = this.ObjectsData[index];
                for (
                  let index = 0;
                  index < fMosthighobjectidsArr.length;
                  index++
                ) {
                  const element1 = fMosthighobjectidsArr[index];
                  if (element.fId == element1) {
                    this.tableData[4].name.push(element);
                  }
                }
              }

              this.tableData[0].amount1 = res.data.fOvertime;

              if (res.data.fIsstarted == 1) {
                this.tableData[0].amount2 = true;
              } else {
                this.tableData[0].amount2 = false;
              }
              this.form.desc = res.data.fTexttemplate;
            }
          } else {
            this.$message.error(res.msg);
          }
        })
        .catch((error) => {
          console.log(error);
          // this.$message.error(error.msg);
        });
    },
    addFormwork_P(data) {
      // 按盘数模版--新增/修改
      addNoticeTemplateByPiece(data)
        .then((res) => {
          if (res.errcode == 0) {
            this.$message.success("保存成功");
            //  this.reload();
            this.getFormwork_P(this.getList.fCompanyid);
          } else {
            this.$message.error(res.msg);
          }
        })
        .catch((error) => {
          console.log(error);
        });
    },

    getFormwork_C(id) {
      // 按每车模版--获取
      getNoticeTemplateByTruck({ fCompanyid: id, fNote: "1" })
        .then((res) => {
          if (res.errcode == 0) {
            if (res.data) {
              this.addList_C.fId = res.data.fId;
              let fLowobjectidsArr = null;
              this.tableData3[0].name = [];
              fLowobjectidsArr = res.data.fLowobjectids.split(",");
              for (let index = 0; index < this.ObjectsData.length; index++) {
                const element = this.ObjectsData[index];
                for (let index = 0; index < fLowobjectidsArr.length; index++) {
                  const element1 = fLowobjectidsArr[index];
                  if (element.fId == element1) {
                    this.tableData3[0].name.push(element);
                  }
                }
              }

              let fMidobjectidsArr = null;
              this.tableData3[1].name = [];
              fMidobjectidsArr = res.data.fMidobjectids.split(",");
              for (let index = 0; index < this.ObjectsData.length; index++) {
                const element = this.ObjectsData[index];
                for (let index = 0; index < fMidobjectidsArr.length; index++) {
                  const element1 = fMidobjectidsArr[index];
                  if (element.fId == element1) {
                    this.tableData3[1].name.push(element);
                  }
                }
              }

              let fHighobjectidsArr = null;
              this.tableData3[2].name = [];
              fHighobjectidsArr = res.data.fHighobjectids.split(",");
              for (let index = 0; index < this.ObjectsData.length; index++) {
                const element = this.ObjectsData[index];
                for (let index = 0; index < fHighobjectidsArr.length; index++) {
                  const element1 = fHighobjectidsArr[index];
                  if (element.fId == element1) {
                    this.tableData3[2].name.push(element);
                  }
                }
              }
              this.tableData3[0].amount1 = res.data.fOvertime;

              if (res.data.fIsstarted == 1) {
                this.tableData3[0].amount2 = true;
              } else {
                this.tableData3[0].amount2 = false;
              }
              this.form3.desc = res.data.fTexttemplate;
            }
          } else {
            this.$message.error(res.msg);
          }
        })
        .catch((error) => {
          console.log(error);
        });
    },
    addFormwork_C(data) {
      // 按每车模版--新增/修改
      addNoticeTemplateByTruck(data)
        .then((res) => {
          if (res.errcode == 0) {
            this.$message.success("保存成功");
            this.getFormwork_C(this.getList.fCompanyid);
          } else {
            this.$message.error(res.msg);
          }
        })
        .catch((error) => {
          console.log(error);
        });
    },
    getFormwork_T(id) {
      // 按一段时间模版--获取
      getNoticeTemplateByTime({ fCompanyid: id, fNote: "1" })
        .then((res) => {
          if (res.errcode == 0) {
            var data = res.data;
            var data1 = [];
            data.map((item) => {
              var fSendobject = {};
              this.ObjectsData.map((i) => {
                if (item.fSendobject == i.fId) {
                  fSendobject = i;
                }
              });
              data1.push({
                fCompanyid: item.fCompanyid,
                fId: item.fId,
                fIsstarted: item.fIsstarted == 0 ? false : true,
                fSendobject: fSendobject,
                fSendperiod: item.fSendperiod,
                fTexttemplate: item.fTexttemplate,
                fUnqualifiedcount: item.fUnqualifiedcount,
                userId: item.userId,
                userName: item.userName,
              });
            });
            this.tableData2 = data1;
            this.form2.desc = this.tableData2[0].fTexttemplate;
          } else {
            this.$message.error(res.msg);
          }
        })
        .catch((error) => {
          console.log(error);
        });
    },
    addFormwork_T(data) {
      // 按一段时间模版--新增/修改
      // console.log("按一段时间模版", data);
      // if (data.length == 0) {

      // } else {

      addNoticeTemplateByTime({ yjQmpMsNoticebytimeList: data })
        .then((res) => {
          if (res.errcode == 0) {
            this.$message.success("保存成功");
            this.getFormwork_T(this.getList.fCompanyid);
          } else {
            this.$message.error(res.msg);
          }
        })
        .catch((error) => {
          console.log(error);
        });
      // }
    },
    getFormwork_D(id) {
      // 按昨日不合格总量模版--获取
      getNoticeTemplateByYesterday({ fCompanyid: id, fNote: "1" })
        .then((res) => {
          if (res.errcode == 0) {
            if (res.data) {
              this.addList_D.fId = res.data.fId;
              let fSendobject = null;
              this.tableData1[0].name = [];
              fSendobject = res.data.fSendobject.split(",");
              for (let index = 0; index < this.ObjectsData.length; index++) {
                const element = this.ObjectsData[index];
                for (let index = 0; index < fSendobject.length; index++) {
                  const element1 = fSendobject[index];
                  if (element.fId == element1) {
                    this.tableData1[0].name.push(element);
                  }
                }
              }

              this.tableData1[0].amount1 = res.data.fSendtime;

              if (res.data.fIsstarted == 1) {
                this.tableData1[0].amount2 = true;
              } else {
                this.tableData1[0].amount2 = false;
              }
              this.form1.desc = res.data.fTexttemplate;
            }
          } else {
            this.$message.error(res.msg);
          }
        })
        .catch((error) => {
          this.$message.error(error.msg);
        });
    },
    addFormwork_D(data) {
      // 按昨日不合格总量模版--新增/修改
      addNoticeTemplateByYesterday(data)
        .then((res) => {
          if (res.errcode == 0) {
            this.$message.success("保存成功");
            this.getFormwork_D(this.getList.fCompanyid);
          } else {
            this.$message.error(res.msg);
          }
        })
        .catch((error) => {
          this.$message.error(error.msg);
        });
    },

    // 预警通知-对象列表页
    yj_ObjectForm(id) {
      var data = {
        fCompanyid: id,
        fNote: "1",
      };
      getNoticeObjectListByCompanyId(data)
        .then((res) => {
          if (res.errcode == 0) {
            this.ObjectsData = res.data;
            this.getFormwork_P(this.getList.fCompanyid);
            this.getFormwork_C(this.getList.fCompanyid);
            this.getFormwork_T(this.getList.fCompanyid);
            this.getFormwork_D(this.getList.fCompanyid);
          } else {
            this.$message.error(res.msg);

            return false;
          }
        })
        .catch((error) => {
          console.log(error);
        });
    },

    // 新增/修改
    yj_editObjectForm(status) {
      if (status == 0) {
        this.addList_p.userId = this.$store.state.userInfo.userId; // 当前用户id
        this.addList_p.userName = this.$store.state.userInfo.realName; // 当前用户name
        let fLowobjectids = "";
        for (let index = 0; index < this.tableData[0].name.length; index++) {
          const element = this.tableData[0].name[index];
          fLowobjectids += element.fId + ",";
        }
        this.addList_p.fLowobjectids = fLowobjectids.slice(
          0,
          fLowobjectids.length - 1
        ); // 初级对象ids

        let fMidobjectids = "";
        for (let index = 0; index < this.tableData[1].name.length; index++) {
          const element = this.tableData[1].name[index];
          fMidobjectids += element.fId + ",";
        }
        this.addList_p.fMidobjectids = fMidobjectids.slice(
          0,
          fMidobjectids.length - 1
        ); // 中级对象ids

        let fHighobjectids = "";
        for (let index = 0; index < this.tableData[2].name.length; index++) {
          const element = this.tableData[2].name[index];
          fHighobjectids += element.fId + ",";
        }
        this.addList_p.fHighobjectids = fHighobjectids.slice(
          0,
          fHighobjectids.length - 1
        ); // 高级对象ids

        let fBetterhighobjectids = "";
        for (let index = 0; index < this.tableData[3].name.length; index++) {
          const element = this.tableData[3].name[index];
          fBetterhighobjectids += element.fId + ",";
        }
        this.addList_p.fBetterhighobjectids = fBetterhighobjectids.slice(
          0,
          fBetterhighobjectids.length - 1
        ); // 四级对象ids

        let fMosthighobjectids = "";
        for (let index = 0; index < this.tableData[4].name.length; index++) {
          const element = this.tableData[4].name[index];
          fMosthighobjectids += element.fId + ",";
        }
        this.addList_p.fMosthighobjectids = fMosthighobjectids.slice(
          0,
          fMosthighobjectids.length - 1
        ); // 五级对象ids

        this.addList_p.fOvertime = this.tableData[0].amount1; // 超出多少周期后不发
        if (this.tableData[0].amount2 == true) {
          this.addList_p.fIsstarted = "1";
        } else {
          this.addList_p.fIsstarted = "0";
        } // 是否启用 1 启用 0-停用

        this.addList_p.fTexttemplate = this.form.desc; // 短信模版
        this.addFormwork_P(this.addList_p);
      } else if (status == 1) {
        // if (this.tableData3[0].amount1=="") {
        //     return this.$message.error("按每车混合料单一材料的重量偏差提醒---超出多少周期后不发 不能为空");

        // }
        this.addList_C.userId = this.$store.state.userInfo.userId; // 当前用户id
        this.addList_C.userName = this.$store.state.userInfo.realName; // 当前用户name

        let fLowobjectids = "";
        for (let index = 0; index < this.tableData3[0].name.length; index++) {
          const element = this.tableData3[0].name[index];
          fLowobjectids += element.fId + ",";
        }
        this.addList_C.fLowobjectids = fLowobjectids.slice(
          0,
          fLowobjectids.length - 1
        ); // 初级对象ids

        let fMidobjectids = "";
        for (let index = 0; index < this.tableData3[1].name.length; index++) {
          const element = this.tableData3[1].name[index];
          fMidobjectids += element.fId + ",";
        }
        this.addList_C.fMidobjectids = fMidobjectids.slice(
          0,
          fMidobjectids.length - 1
        ); // 中级对象ids

        let fHighobjectids = "";
        for (let index = 0; index < this.tableData3[2].name.length; index++) {
          const element = this.tableData3[2].name[index];
          fHighobjectids += element.fId + ",";
        }
        this.addList_C.fHighobjectids = fHighobjectids.slice(
          0,
          fHighobjectids.length - 1
        ); // 高级对象ids

        this.addList_C.fOvertime = this.tableData3[0].amount1; // 超出多少周期后不发
        if (this.tableData3[0].amount2 == true) {
          this.addList_C.fIsstarted = "1";
        } else {
          this.addList_C.fIsstarted = "0";
        } // 是否启用 1 启用 0-停用

        this.addList_C.fTexttemplate = this.form3.desc; // 短信模版

        this.addFormwork_C(this.addList_C);
      } else if (status == 2) {
        var data = [];
        var fIsstarted;
        var num = 0;
        if (this.tableData2.length != 0) {
          this.tableData2.map((item, index) => {
            if (item.fSendobject.fId == undefined) {
              num++;
              console.log(99999, num);
              this.$message.error(
                "按照一段时间内不合格的盘数提醒---第" +
                  (index - 0 + 1) +
                  "次发送对象不能为空"
              );
              return false;
            } else if (item.fSendperiod == "") {
              num++;
              this.$message.error(
                "按照一段时间内不合格的盘数提醒---第" +
                  (index - 0 + 1) +
                  "次发送周期不能为空"
              );
              return false;
            } else if (item.fUnqualifiedcount == "") {
              num++;
              this.$message.error(
                "按照一段时间内不合格的盘数提醒---第" +
                  (index - 0 + 1) +
                  "次不合格盘数不能为空"
              );
              return false;
            }
            console.log("iiiiii", num);
          });
          console.log(this.tableData2);
          if (num == 0) {
            this.tableData2.map((item) => {
              if (item.fIsstarted == true) {
                fIsstarted = "1";
              } else if (item.fIsstarted == false) {
                fIsstarted = "0";
              }
              data.push({
                fId: "", // 不传或传空字符串
                userName: this.$store.state.userInfo.realName, // 当前登陆人名称
                userId: this.$store.state.userInfo.userId, // 当前登陆人id
                fCompanyid: this.getList.fCompanyid, // 施工标段id
                fSendobject: item.fSendobject.fId, // 发送对象id
                fSendperiod: item.fSendperiod, // 发送周期
                fUnqualifiedcount: item.fUnqualifiedcount, // 不合格盘数
                fIsstarted: fIsstarted, // 是否启动 0-否   1-是
                fTexttemplate: this.form2.desc, // 短信模版
                fNote: "1",
              });

              console.log(data);
            });
            this.addFormwork_T(data);
          }
        } else {
          data.push({
            fId: "", // 不传或传空字符串
            userName: "", // 当前登陆人名称
            userId: "", // 当前登陆人id
            fCompanyid: this.getList.fCompanyid, // 施工标段id
            fSendobject: "", // 发送对象id
            fSendperiod: "", // 发送周期
            fUnqualifiedcount: "", // 不合格盘数
            fIsstarted: "", // 是否启动 0-否   1-是
            fTexttemplate: "", // 短信模版
            fNote: "1",
          });
          this.addFormwork_T(data);
          // return this.$message.error(
          //   "请先添加数据"
          // );
        }
      } else if (status == 3) {
        if (this.tableData1[0].name.length == 0) {
          return this.$message.error(
            "昨日不合格总量进行提醒---报警对象不能为空"
          );
        } else if (this.tableData1[0].amount1 == "") {
          return this.$message.error(
            "昨日不合格总量进行提醒---发送时间不能为空"
          );
        } else {
          if (this.tableData1[0].amount2 == true) {
            this.addList_D.fIsstarted = "1";
          } else {
            this.addList_D.fIsstarted = "0";
          } // 是否启用 0-禁用 1-启用

          let fSendobject_D = "";
          for (let index = 0; index < this.tableData1[0].name.length; index++) {
            const element = this.tableData1[0].name[index];
            fSendobject_D += element.fId + ",";
          }
          this.addList_D.fSendobject = fSendobject_D.slice(
            0,
            fSendobject_D.length - 1
          ); // 发送对象
          this.addList_D.userId = this.$store.state.userInfo.userId; // 当前登陆用户id
          this.addList_D.userName = this.$store.state.userInfo.realName; // 当前用户name
          this.addList_D.fSendtime = this.tableData1[0].amount1; //发送时间
          this.addList_D.fTexttemplate = this.form1.desc; //短信模版

          this.addFormwork_D(this.addList_D);
        }
      }
    },

    // 所属对象数据
    selectEquipmen() {
      // selectEquipmen(row, list) {
      // console.log(this.fEquipmentname，row，list);

      var arr = [];
      this.fEquipmentname.map((item) => {
        arr.push(item.fId);
      });
      // fId
      // this.formData.fObjects = arr.join(",");
    },

    // 多选方法
    selectionChange() {},
    // 排序方法
    sortChange() {},
  },
};
</script>
  
<style scoped lang="less">
.warningObject_table {
  display: flex;
  height: 100%;
}

.saveBtn {
  display: flex;
  justify-content: flex-end;
  align-items: center;
  margin-top: 15px;
  padding: 7px 40px 0px;
  border-top: 1px solid #eee;
}

.collapse-itemContent {
  width: 100%;
  overflow-y: auto;
  padding: 0 10px;
  box-sizing: border-box;
}

.customTable {
  display: flex;
  height: 100%;
  justify-content: flex-end;
  align-items: center;
  padding-right: 30px;
}

.pageFlag {
  width: 100%;
  height: 100%;
  display: flex;
  flex-direction: column;

  justify-content: center;
  align-items: center;
  color: #171a1d;
  font-size: 16px;
  // background: pink;

  img {
    width: 258px;
    height: 208px;
  }

  .pageFlagText {
    margin-top: 33px;
  }

  .pageFlagTexts {
    font-size: 14px;
    color: #a2a4a7;
  }
}

.customTable /deep/.cell {
  height: 100%;
  display: flex;
  align-items: center;
}

.customTable /deep/.el-button {
  width: 25px;

  display: flex;
  justify-content: center;
  align-items: center;
}

.collapse-itemContent /deep/.el-collapse-item__content {
  padding-bottom: 7px !important;
}

.collapse-itemContent /deep/.el-input__inner {
  padding: 0 0 0 15px !important;
}

.shortMessageform /deep/.el-form-item {
  display: flex !important;
}

.shortMessageform /deep/.el-form-item__label {
  text-align: center;
}

.shortMessageform /deep/.el-form-item__content {
  margin-left: 0 !important;

  flex: 1;
}

.selectobject /deep/.el-input__icon {
  line-height: 22px;
}

.inputminute /deep/.el-input {
  width: 55px;
  margin: auto;
}
</style>